﻿using Rabbit.Domain.Entity;
using Rabbit.Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rabbit.Domain.Repository
{
    public class GoodInfoRepository : IGoodInfoRepository
    {
        private readonly RbacContext _context;

        public GoodInfoRepository(RbacContext context)
        {
            _context = context;
        }

        /// <summary>
        /// 删除（单删）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetDelGoodInfo(int id)
        {
            var list = _context.Goodinfos.Find(id);
            list.IsDel =1;
            _context.Goodinfos.Update(list);
            return _context.SaveChanges();

        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public dynamic GetFindGoodinfo(int id)
        {
            return _context.Goodinfos.FirstOrDefault(x => x.GoodInfoId == id);
        }

        public int GetGoodInfoAdd(Goodinfo good)
        {
            _context.Goodinfos.Add(good);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 跳转页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Goodinfo> GetGoodInfoImage(int id)
        {
           var list=_context.Goodinfos.Where(x=>x.GoodInfoId == id).ToList();
            return list;
        }

        public List<Goodinfo> GetGoodInfoList()
        {
            
            return _context.Goodinfos.Where(x=>x.IsDel==0).ToList();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="good"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetGoodInfoUpdate(Goodinfo good)
        {
           var list=_context.Goodinfos.FirstOrDefault(x=>x.GoodInfoId==good.GoodInfoId);
            list.Information= good.Information;
             list.Production= good.Production;
             list.GoodInfoId= good.GoodInfoId;
             list.GoodId= good.GoodId;
             list.Shelflife= good.Shelflife;
             list.CreateName= good.CreateName;
             list.UpdateName= good.UpdateName;
             list.Batch= good.Batch;
             list.CreateTime= good.CreateTime;
            list.GoodCompany = good.GoodCompany;
            list.Information=good.Information;
            list.GoodImages= good.GoodImages;
            _context.Goodinfos.Update(list);
            return _context.SaveChanges();
            
        }
    }
}
